Completed
Push — master ( 3f76fd...7863ed )
by Thomas
30s
created

Kits.list   B

Complexity

Conditions 2
Paths 5

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
nc 5
nop 1
dl 0
loc 28
rs 8.8571
c 2
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A 0 20 3
1
'use strict'
2
3
const util = require('../util')
4
5
const Kits = {
6
  cache: []
7
}
8
9
Kits.list = function (callback) {
10
  if (Kits.cache.length) {
11
    callback(Kits.cache)
12
    return
13
  }
14
15
  var stopSpinner = util.output.wait('Loading available starter kits')
16
  util.request('kits/short').end(function (response) {
17
    if (response.error || !response.body) {
18
      stopSpinner(response.error)
19
      process.exit()
20
    }
21
22
    stopSpinner()
23
    var list = response.body.data.sort(function (a, b) {
24
      if (a === 'basic') {
25
        return -1
26
      }
27
      if (b === 'basic') {
28
        return 1
29
      }
30
      return a > b ? 1 : -1
31
    })
32
33
    Kits.cache = list
34
    callback(list)
35
  })
36
}
37
38
module.exports = Kits
39